package com.honghu.cloud.controller;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.honghu.cloud.redis.RedisUtil;
import com.honghu.cloud.service.ISeckillGoodsService;
import com.honghu.cloud.utils.Exceptions;

import lombok.extern.slf4j.Slf4j;
import net.sf.json.JSONObject;

@Slf4j
@RestController
@Configuration
@RequestMapping(value = "/secKillTimer")
public class GoodsSeckillTimerController {
	
	private static final Logger logger = LoggerFactory.getLogger(GoodsSeckillTimerController.class);
	
	@Autowired
	private RedisUtil redisUtil;
	@Autowired
	private ISeckillGoodsService seckillGoodsService;
	
	/**
	 *  定时器执行秒杀活动(秒杀结束可晚点)
	 */
	@Scheduled(cron = "0 0/1 * * * ?")
	//@Scheduled(cron = "0 0 0/1 * * ? ")
	public void items() {
		System.out.println("spring..minuteTimer.....");
		
		try {
			// 秒杀开始
			seckillGoodsService.secondKillBegins2();
		} catch (Exception e) {
			logger.error(Exceptions.getStackTraceAsString(e));
		}
		try {
			// 秒杀开始
			seckillGoodsService.secondKillBegins();
		} catch (Exception e) {
			logger.error(Exceptions.getStackTraceAsString(e));
		}
		try {
			// 秒杀结束  
			seckillGoodsService.secondKillEnd();
		} catch (Exception e) {
			logger.error(Exceptions.getStackTraceAsString(e));
		}
		
		/*try {
			// 订单未付款, 秒杀商品返还, 联调代
			seckillGoodsService.secondKillNoPay();
		} catch (Exception e) {
			logger.error(Exceptions.getStackTraceAsString(e));
		}*/
	}
	
	
	

	
}
